home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-13 | 4.6 KB | 183 lines | [TEXT/KAHL] |
- ///--------------------------------------------------------------------------------------
- // ShipSprite.h
- //
- // Created: 6/18/92 at 2:29:31 PM
- // By: Tony Myles
- //
- // Copyright © 1992 Tony Myles, All rights reserved worldwide.
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __SHIPSPRITE__
- #define __SHIPSPRITE__
-
- #ifndef __SPRITEWORLD__
- #include <SpriteWorld.h>
- #endif
-
- #ifndef __SPRITELAYER__
- #include <SpriteLayer.h>
- #endif
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
-
- // spaceship constants
- enum
- {
- kNumberOfShipSprites = 1,
- kNumberOfShipFrames = 30,
- kNumberOfExplosionFrames = 0,
- kTotalFrames = kNumberOfShipFrames + kNumberOfExplosionFrames,
- kFirstShipFrame = 0,
- kLastShipFrame = kNumberOfShipFrames - 1,
- kFirstExplosionFrame = kNumberOfShipFrames,
- kLastExplosionFrame = kFirstExplosionFrame + (kNumberOfExplosionFrames - 1),
- kShipFrameResID = 1000,
- kExplosionFrameResID = 2000,
- kExplosionSoundResID = 1000,
- kThrustSoundResID = 1001,
- kMaxShipVelocity = 18,
- kShipMoveTime = 30,
- kShipFrameTime = 30,
- kExplosionTickDelay = 15
- };
-
- // space shot constants
- enum
- {
- kShotFrameResID = 2000,
- kShotSoundResID = 1002,
- kNumberOfShotSprites = 10,
- kNumberOfShotFrames = 1,
- kShotIntervalTicks = 6,
- kShotSpeedFactor = 10,
- kShotMoveTime = 16,
- kShotLifeExpectancy = 20,
- kShotPosOffset = 14
- };
-
-
- typedef Fixed Coordinate;
-
- // velocity data structure
- typedef struct
- {
- Coordinate h;
- Coordinate v;
- } Velocity;
-
-
- typedef struct ShotSpriteRec ShotSpriteRec;
- typedef ShotSpriteRec *ShotSpritePtr, **ShotSpriteHdl;
- typedef struct ShipSpriteRec ShipSpriteRec;
- typedef ShipSpriteRec *ShipSpritePtr, **ShipSpriteHdl;
-
- struct ShotSpriteRec
- {
- // shot spriteworld stuff
- SpriteRec shotSprite;
-
- // shot movement stuff
- Velocity shotVelocity;
- Coordinate shotHorizLoc;
- Coordinate shotVertLoc;
-
- // other shot stuff
- ShipSpritePtr shipSpriteP;
- long shotLife;
- };
-
-
- // space ship data structure
- struct ShipSpriteRec
- {
- // ship spriteworld stuff
- SpriteRec shipSprite;
- SpriteWorldPtr shipSpriteWorldP;
- SpriteLayerPtr shipSpriteLayerP;
- SpriteLayerPtr shotSpriteLayerP;
- Rect shipWrapRect;
-
- // ship movement stuff
- Velocity shotVelocityTable[kNumberOfShipFrames];
- Velocity angularVelocityTable[kNumberOfShipFrames];
- Velocity shipVelocity;
- Coordinate shipHorizLoc;
- Coordinate shipVertLoc;
-
- // ship shot stuff
- ShotSpritePtr shotSpriteArray[kNumberOfShotSprites];
- ShotSpriteRec shotSpriteStorage[kNumberOfShotSprites];
- short shotCounter;
- long shotTickDelay;
-
- // ship sound stuff
- SndChannelPtr shipSndChannelP;
- SndChannelPtr shotSndChannelP;
- SndCommand shipSndCmd;
- SndCommand shotSndCmd;
- Handle thrustSndH;
- Handle shotSndH;
- Handle explosionSndH;
-
- // ship miscellaneous stuff
- Boolean isAlive;
- };
-
-
- // fixed point math stuff
- #define ff(x) ((Fixed)(((long)(x)) << 16))
- #define FixToShort(x) ((short)((x) >> 16))
- #define FixToDbl(x) ldexp((double)(x), -16)
- #define DblToFix(x) ((Fixed)ldexp((x), 16))
- #define RndFixToInt(x) ((int)((x)+FIX_HALF >> 16))
- #define FixRound(x) FixToi(x)
- #define Frac2Fix(x) ((x)>>14)
- #define Fix2Frac(x) ((x)<<14)
- #define FracToDbl(x) ldexp((double)(x), -30)
- #define DblToFrac(x) ((long)ldexp((x), 30))
-
- // keyboard constants
- enum
- {
- kUpArrowKey = 0x7E,
- kLeftArrowKey = 0x7B,
- kRightArrowKey = 0x7C,
- kSpaceBarKey = 0x31,
- kCommandKey = 0x37,
- kOptionKey = 0x3A,
- kShiftKey = 0x38,
- kEscapeKey = 0x35
- };
-
- #define KeyMapLoMem ((unsigned char *)0x174)
- #define KeyIsDown(key) ((KeyMapLoMem[key >> 3] >> (key & 7)) & 1)
-
-
- // miscellaneous constants
- #define kRadiansInCircle 6.283185307178
-
-
- // function prototypes
- OSErr CreateShipSprite(ShipSpritePtr* shipSpriteP);
- void InitShipSprite(ShipSpritePtr shipSpriteP, SpriteWorldPtr spriteWorldP, SpriteLayerPtr shipSpriteLayerP, SpriteLayerPtr shotSpriteLayerP);
- void DisposeShipSprite(ShipSpritePtr shipSpriteP);
- OSErr CreateShipSounds(ShipSpritePtr shipSpriteP);
- void DisposeShipSounds(ShipSpritePtr shipSpriteP);
- void SetupShipSprite(ShipSpritePtr shipSpriteP);
- OSErr CreateShotSpriteArray(ShipSpritePtr shipSpriteP);
- void InitShotSprite(ShipSpritePtr shipSpriteP, ShotSpritePtr shotSpriteP);
- void DisposeShotSprite(ShipSpritePtr shipSpriteP);
- void CreateVelocityTable(Velocity *velocityTable, short numAngles, double radius);
- void FireAShot(ShipSpritePtr shipSpriteP);
- void ShipMoveProc(ShipSpritePtr shipSpriteP, Point *spriteLoc);
- void ShipFrameProc(ShipSpritePtr shipSpriteP, FramePtr curFrameP, long* curFrameIndex);
- void ShipCollideProc(ShipSpritePtr shipSpriteP, SpritePtr dstSpriteP, Rect* sectRect);
- void ShotMoveProc(ShotSpritePtr shotSpriteP, Point *spriteLoc);
-
- pascal void ShipSoundCallBack(SndChannelPtr sndChannelP, SndCommand *sndCmdP);
-
- #endif /* __SHIPSPRITE__ */